<template>
 <div>
    <el-dialog title="简历正文" width="80%" :visible.sync="dialogContentVisible" append-to-body>
      <tinymce :height="600"  v-model="content"></tinymce>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updateContentData">{{$t('table.confirm')}}</el-button>
      </span>
    </el-dialog>
    <el-dialog title="推荐报告" :visible.sync="dialogVisible" :fullscreen="true" :before-close="handleClose" append-to-body>
      <el-form  :inline="true"  ref="dataForm" size="mini" :model="temp" label-width="150px" >
        <div class="form-row">
          <el-form-item label="简历" prop="title" class="form-item-full">
            <el-button icon='el-icon-edit' size="small" plain @click="showContent">简历正文</el-button>
            <el-button icon='el-icon-download' size="small" plain @click="showContent">下载</el-button>
            <el-button icon='el-icon-printer' size="small" plain @click="showContent">打印</el-button>
          </el-form-item>
        </div>
        <div class="form-content">
          <div class="form-header"> <span class="form-header-title">推荐报告</span></div>
          <div class="form-row">
            <el-form-item label="整体年薪" prop="title" class="form-item-full">
              <el-input v-model="temp.report.total_annual_salary" style="width: 420px;" ></el-input>
            </el-form-item>
            <el-form-item label="薪资构成" prop="title" class="form-item-full">
              <el-input v-model="temp.report.salary_structure" style="width: 420px;" ></el-input>
            </el-form-item>
            <el-form-item label="期望薪资" prop="title" class="form-item-full">
              <el-input v-model="temp.report.expected_salary" style="width: 420px;" ></el-input>
            </el-form-item>
            <el-form-item label="优势劣势" prop="title" class="form-item-full">
              <el-input  type="textarea" :rows="4" v-model="temp.report.self_desc" style="width: 420px;" ></el-input>
            </el-form-item>
            <el-form-item label="职业意向" prop="title" class="form-item-full">
              <el-input v-model="temp.report.career_intention" style="width: 420px;" ></el-input>
            </el-form-item>
            <el-form-item label="性格特点" prop="title" class="form-item-full">
              <el-input v-model="temp.report.character_desc" style="width: 420px;" ></el-input>
            </el-form-item>
            <el-form-item label="期望面试时间" prop="title" class="form-item-full">
              <el-input v-model="temp.report.expected_interview_time" style="width: 420px;" ></el-input>
            </el-form-item>
            <el-form-item label="预计到岗时间" prop="title" class="form-item-full">
              <el-input v-model="temp.report.expected_arrival_time" style="width: 420px;" ></el-input>
            </el-form-item>
          </div>
        </div>
        <div class="form-content">
          <div class="form-header"> <span class="form-header-title">自我介绍</span></div>
          <div class="form-row">
            <el-form-item label="介绍" class="form-item-full">
              <el-input type="textarea" :rows="4" size="small" v-model="temp.self_introduction" style="width: 480px;"></el-input>
            </el-form-item>
          </div>
        </div>
        <div class="form-content">
          <div class="form-header"> <span class="form-header-title">基本信息</span></div>
          <div class="form-row">
            <el-form-item label="姓  名" prop="title" class="form-item">
              <el-input v-model="temp.candidate_name" style="width: 200px;" ></el-input>
            </el-form-item>
            <el-form-item label="性  别" prop="title" class="form-item">
              <el-select style="width: 200px;" v-model="temp.gender" placeholder="请选择">
                <el-option v-for="item in genderOptions " :key="item.key" :label="item.display_name" :value="item.key">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="出生年月" prop="title" class="form-item">
              <el-date-picker
                v-model="temp.birthday_date"
                type="month"
                format="yyyy-MM" value-format="timestamp" 
                style="width: 200px;">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="婚育情况" prop="title" class="form-item">
              <el-select style="width: 200px;" v-model="temp.marriage" placeholder="请选择">
                <el-option v-for="item in  marriageOptions" :key="item.key" :label="item.display_name" :value="item.key">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="户  籍" prop="title" class="form-item">
              <el-cascader v-model="residence_arr" 
                :options="city_cascader_options"
                :show-all-levels="false"
                :change-on-select="true"
                @change ="handleResidenceItemChange">
              </el-cascader> 
            </el-form-item>
            <el-form-item label="所在城市" prop="title" class="form-item">
              <el-cascader v-model="city_arr" 
                :options="city_cascader_options"
                :show-all-levels="false"
                :change-on-select="true"
                @change ="handleCityItemChange">
              </el-cascader> 
            </el-form-item>
            <el-form-item label="手  机" prop="title" class="form-item">
              <el-input v-model="temp.mobile_phone" style="width: 200px;" ></el-input>
            </el-form-item>
            <el-form-item label="邮  箱" prop="title" class="form-item">
              <el-input v-model="temp.email" style="width: 200px;" ></el-input>
            </el-form-item>
            <el-form-item label="Q  Q" prop="title" class="form-item">
              <el-input v-model="temp.qq" style="width: 200px;" ></el-input>
            </el-form-item>
            <el-form-item label="微  信" prop="title" class="form-item">
              <el-input v-model="temp.weixin" style="width: 200px;" ></el-input>
            </el-form-item>
            <el-form-item label="最高学历" prop="title" class="form-item">
              <el-select v-model="temp.highest_diploma" filterable placeholder="请选择">
                <el-option
                  v-for="item in education_backgroud_options"
                  :key="item.id"
                  :label="item.label"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="毕业年月" prop="title" class="form-item">
              <el-date-picker
                v-model="temp.graduation_date"
                type="month"
                format="yyyy-MM" value-format="timestamp" 
                style="width: 200px;">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="语言能力" prop="title" class="form-item">
            <treeselect
              class="select-item" 
              :multiple="true"
              :options="language_level_options"
              :load-options="loadChildrenOptions"
              :valueConsistsOf="valueConsistsOf"
              placeholder="请选择"
              v-model="temp.language_level_group"
            />
            </el-form-item>
            <el-form-item label="意向城市" prop="title" class="form-item">
              <treeselect
              class="select-item" 
              :multiple="true"
              :options="city_options"
              :load-options="loadChildrenOptions"
              :valueConsistsOf="valueConsistsOf"
              placeholder="请选择"
              v-model="temp.preferred_city_group"
              />
            </el-form-item>
             <el-form-item label="当前公司" prop="title" class="form-item-full">
              <el-input v-model="temp.company_name" style="width: 400px;" ></el-input>
            </el-form-item>
            <el-form-item label="当前职位" prop="title" class="form-item">
              <el-input v-model="temp.position" style="width: 200px;" ></el-input>
            </el-form-item>
            <el-form-item label="当前年薪" prop="title" class="form-item">
              <el-input v-model="temp.annual_salary" style="width: 240px;" ></el-input>
            </el-form-item>
          </div>
        </div>
        <div class="form-content">
          <div class="form-header"> 
            <span class="form-header-title">教育经历</span>
            <span class="form-header-button">
              <el-button plain size="small" v-on:click="addEducationItem">添加</el-button>
            </span>
          </div>
          <div class="form-table-border" v-for="(item,index) in this.temp.education_items" :key="index" >
            <el-form-item label="学校" class="form-item">
                <el-input  v-model="temp.education_items[index].school" style="width: 240px;" ></el-input>
            </el-form-item>
            <el-form-item label="时间" class="form-item">
              <el-date-picker
                v-model="temp.education_items[index].start_date"
                type="month"
                format="yyyy-MM" value-format="timestamp" 
                style="width: 110px;">
              </el-date-picker>
              <span>-></span>
              <el-date-picker
                v-model="temp.education_items[index].end_date"
                type="month"
                format="yyyy-MM" value-format="timestamp" 
                style="width: 110px;">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="学位" class="form-item">
              <el-select v-model="temp.education_items[index].diploma" filterable placeholder="请选择">
                <el-option
                  v-for="item in education_backgroud_options"
                  :key="item.id"
                  :label="item.label"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="专业" class="form-item">
                <el-input size="small" v-model="temp.education_items[index].major" style="width: 240px;"></el-input>
            </el-form-item>
            <el-form-item label="统招" class="form-item">
              <el-radio v-model="temp.education_items[index].is_unified" label="1">是</el-radio>
              <el-radio v-model="temp.education_items[index].is_unified" label="0">不限</el-radio>
            </el-form-item>
            <el-form-item label="删除" class="form-item">
              <i class="el-icon-delete" v-on:click="removeEducationItem(index)"></i>
            </el-form-item>
          </div>
        </div>
        <div class="form-content">
          <div class="form-header"> 
            <span class="form-header-title">技能证书</span>
            <span class="form-header-button">
              <el-button plain size="small" v-on:click="addSkillCertItem">添加</el-button>
            </span>
          </div>
          <div class="form-table-border" v-for="(item,index) in this.temp.skill_certificate_group" :key="index" >
            <el-form-item label="证书" class="form-item-full">
              <el-input v-model="temp.skill_certificate_group[index]" style="width: 240px;" ></el-input>
              <i class="el-icon-delete" v-on:click="removeSkillCertItem(index)"></i>
            </el-form-item>
          </div> 
        </div>
        <div class="form-content">
          <div class="form-header"> 
            <span class="form-header-title">工作经历</span>
            <span class="form-header-button">
              <el-button plain size="small" v-on:click="addExperienceItem">添加</el-button>
            </span>
          </div>
          <div class="form-table-border" v-for="(item,index) in this.temp.experience_items" :key="index" >
            <el-form-item label="时间" class="form-item-full">
              <el-date-picker
                v-model="temp.experience_items[index].start_date"
                type="month"
                format="yyyy-MM" value-format="timestamp" 
                style="width: 110px;">
              </el-date-picker>
              <span>-></span>
              <span v-show="temp.experience_items[index].is_current">至今</span>
              <el-date-picker
                v-model="temp.experience_items[index].end_date"
                type="month"
                format="yyyy-MM" value-format="timestamp"
                v-show="!temp.experience_items[index].is_current"
                style="width: 110px;">
              </el-date-picker>
              <span>
                <el-checkbox v-model="temp.experience_items[index].is_current" >目前在职</el-checkbox>
              </span>
            </el-form-item>
            <el-form-item label="公司" class="form-item-full">
              <el-input size="small" v-model="temp.experience_items[index].company_name" style="width: 480px;"></el-input>
            </el-form-item>
            <el-form-item label="职位" class="form-item">
              <el-input size="small" v-model="temp.experience_items[index].function" style="width: 240px;"></el-input>
            </el-form-item>
            <el-form-item label="部门" class="form-item">
              <el-input size="small" v-model="temp.experience_items[index].dept_name" style="width: 240px;"></el-input>
            </el-form-item>
            <el-form-item label="汇报对象" class="form-item">
              <el-input size="small" v-model="temp.experience_items[index].leader" style="width: 240px;"></el-input>
            </el-form-item>
            <el-form-item label="下属人数" class="form-item">
              <el-input size="small" v-model="temp.experience_items[index].subordinates_num" style="width: 240px;"></el-input>
            </el-form-item>
            <el-form-item label="工作内容" class="form-item-full">
              <el-input type="textarea" :rows="4" size="small" v-model="temp.experience_items[index].work_content" style="width: 480px;"></el-input>
            </el-form-item>
            <el-form-item label="工作业绩" class="form-item-full">
              <el-input type="textarea" :rows="4" size="small" v-model="temp.experience_items[index].work_performance" style="width: 480px;"></el-input>
            </el-form-item>
            <el-form-item label="离职原因" class="form-item-full">
              <el-input type="textarea" :rows="2" size="small" v-model="temp.experience_items[index].off_reason" style="width: 480px;"></el-input>
            </el-form-item>
            <el-form-item label="删除" class="form-item">
              <i class="el-icon-delete" v-on:click="removeExperienceItem(index)"></i>
            </el-form-item>
          </div>
        </div>
        <div class="form-content">
         <div class="form-header"> 
            <span class="form-header-title">项目经验</span>
            <span class="form-header-button">
              <el-button plain size="small" v-on:click="addProductItem">添加</el-button>
            </span>
          </div>
          <div class="form-table-border" v-for="(item,index) in this.temp.product_items" :key="index" >
            <el-form-item label="时间" class="form-item-full">
              <el-date-picker
                v-model="temp.product_items[index].start_date"
                type="month"
                format="yyyy-MM" value-format="timestamp" 
                style="width: 110px;">
              </el-date-picker>
              <span>-></span>
              <span v-show="temp.product_items[index].is_current">至今</span>
              <el-date-picker
                v-model="temp.product_items[index].end_date"
                type="month"
                format="yyyy-MM" value-format="timestamp"
                 v-show="!temp.product_items[index].is_current"
                style="width: 110px;">
              </el-date-picker>
              <span>
                <el-checkbox v-model="temp.product_items[index].is_current" >目前在职</el-checkbox>
              </span>
            </el-form-item>

            <el-form-item label="项目名称" class="form-item-full">
              <el-input size="small" v-model="temp.product_items[index].product_name" style="width: 400px;"></el-input>
            </el-form-item>
            <el-form-item label="项目简介" class="form-item-full">
              <el-input type="textarea" :rows="2" size="small" v-model="temp.product_items[index].product_desc" style="width: 400px;"></el-input>
            </el-form-item>
            <el-form-item label="项目职务" class="form-item-full">
              <el-input size="small" v-model="temp.product_items[index].product_position" style="width: 400px;"></el-input>
            </el-form-item>
            <el-form-item label="项目职责" class="form-item-full">
              <el-input type="textarea" :rows="2" size="small" v-model="temp.product_items[index].product_function" style="width: 400px;"></el-input>
            </el-form-item>
            <el-form-item label="项目业绩" class="form-item-full">
              <el-input type="textarea" :rows="2" size="small" v-model="temp.product_items[index].product_achievement" style="width: 400px;"></el-input>
            </el-form-item>
            <el-form-item label="删除" class="form-item">
              <i class="el-icon-delete" v-on:click="removeProductItem(index)"></i>
            </el-form-item>
          </div>
        </div>

        <div class="form-content">
          <div class="form-header"> <span class="form-header-title">培训经历</span></div>
          <div class="form-row">
            <el-form-item label="介绍" class="form-item-full">
              <el-input type="textarea" :rows="4" size="small" v-model="temp.training_experience" style="width: 480px;"></el-input>
            </el-form-item>
          </div>
        </div>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="handleCancel">{{$t('table.cancel')}}</el-button>
        <el-button v-show="this.temp && 'add_project' == this.temp.cv_status" type="primary" @click="updateDataAndSendToManager">推送给客户经理</el-button>
        <el-button type="primary" @click="updateData">保存</el-button>
      </div>
    </el-dialog>
 </div>
</template>
<script>

import Tinymce from '@/components/Tinymce'
import API from '@/utils/backend_api'
import Static_Data from '@/data/index'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
const simulateAsyncOperation = fn => {
  setTimeout(fn, 200)
}
const cityCascaderOptions = Static_Data.city.map((item) => {
  const item_children = []
  if (item.children && item.children.length > 0) {
    item.children.map(function(subitem) {
      item_children.push({ value: subitem.id, label: subitem.label })
    })
  }
  return { value: item.id, label: item.label, children: item_children }
})

export default {
  name: 'candidateReport',
  props: {
    id: {
      type: String,
      default: '' // 这样可以指定默认的值
    },
    visible: {
      type: Boolean,
      default: false // 这样可以指定默认的值
    }
  },
  components: { Treeselect, Tinymce },
  data() {
    return {
      valueConsistsOf: 'ALL',
      content: '',
      dialogContentVisible: false,
      residence_arr: [],
      city_arr: [],
      city_options: Static_Data.city,
      city_cascader_options: cityCascaderOptions,
      marriageOptions: Static_Data.marriage,
      genderOptions: Static_Data.gender,
      language_level_options: Static_Data.language_level,
      education_backgroud_options: Static_Data.education_backgroud,
      temp: {
        cv_status: '',
        education_items: [{
          start_date: '',
          end_date: '',
          diploma: '',
          school: '',
          major: '',
          is_unified: '0'
        }],
        experience_items: [{
          start_date: '',
          end_date: '',
          company_name: '',
          position: '',
          dept_name: '',
          work_content: '',
          off_reason: '',
          work_performance: '',
          leader: '',
          subordinates_num: '',
          is_current: false
        }],
        product_items: [{
          product_name: '',
          product_desc: '',
          start_date: '',
          end_date: '',
          is_current: false,
          product_function: '',
          product_position: '',
          product_achievement: '',
          company_name: ''
        }],
        skill_certificate_group: [''],
        report: {
          salary_structure: '',
          total_annual_salary: '',
          expected_salary: '',
          self_desc: '',
          character_desc: '',
          career_intention: '',
          expected_interview_time: '',
          expected_arrival_time: ''
        }
      },
      dialogStatus: '',
      dialogVisible: false,
      textMap: {
        update: '编辑人才',
        create: '新增人才'
      },
      fileList: [
      ],
      project_options: [{
        value: '1',
        label: '黄金糕'
      }],
      project: ''
    }
  },
  filters: {
  },
  created() {
  },
  watch: {
    id: function(val, oldVal) {
      if (this.id !== '') {
        API.cv.get(val).then(response => {
          this.temp = response.data
          if (this.temp.experience_items && this.temp.experience_items.length > 0) {
            this.temp.experience_items = this.temp.experience_items.map(item => {
              if (item.is_current === '1') {
                item.is_current = true
              } else {
                item.is_current = false
              }
              return item
            })
          }
          if (this.temp.product_items && this.temp.product_items.length > 0) {
            this.temp.product_items = this.temp.product_items.map(item => {
              if (item.is_current === '1') {
                item.is_current = true
              } else {
                item.is_current = false
              }
              return item
            })
          }
          if (this.temp.city) {
            if (this.temp.city.length === 2) {
              this.city_arr = [this.temp.city]
            }
            if (this.temp.city.length === 4) {
              this.city_arr = [this.temp.city.substr(0, 2), this.temp.city]
            }
          }
          if (this.temp.residence) {
            if (this.temp.residence.length === 2) {
              this.residence_arr = [this.temp.residence]
            }
            if (this.temp.residence.length === 4) {
              this.residence_arr = [this.temp.residence.substr(0, 2), this.temp.residence]
            }
          }
          if (this.temp.language_level_group) {
            this.temp.language_level_group = JSON.parse(this.temp.language_level_group)
          }
          if (this.temp.company_group) {
            this.temp.company_group = JSON.parse(this.temp.company_group)
          }
          if (this.temp.school_tag_group) {
            this.temp.school_tag_group = JSON.parse(this.temp.school_tag_group)
          }
          if (this.temp.preferred_city_group) {
            this.temp.preferred_city_group = JSON.parse(this.temp.preferred_city_group)
          }
          if (this.temp.skill_certificate_group) {
            this.temp.skill_certificate_group = JSON.parse(this.temp.skill_certificate_group)
          }
        })
      }
    },
    visible: function(val, oldVal) {
      console.log('当前值为：' + val, '旧值为：' + oldVal)
      this.dialogVisible = val
    }
  },
  computed: {
  },
  methods: {
    updateContentData() {
    },
    showContent() {
      this.dialogContentVisible = true
    },
    handleResidenceItemChange(arr) {
      if (arr && arr.length > 0) {
        this.temp.residence = arr[arr.length - 1]
      }
    },
    handleCityItemChange(arr) {
      if (arr && arr.length > 0) {
        this.temp.city = arr[arr.length - 1]
      }
    },
    addSkillCertItem() {
      this.temp.skill_certificate_group.push('')
    },
    removeSkillCertItem(index) {
      this.temp.skill_certificate_group.splice(index, 1)
    },
    addEducationItem() {
      this.temp.education_items.push({
        start_date: '',
        end_date: '',
        diploma: '',
        school: '',
        major: '',
        is_unified: '1'
      })
    },
    removeEducationItem(index) {
      this.temp.education_items.splice(index, 1)
    },
    addExperienceItem() {
      this.temp.experience_items.push({
        start_date: '',
        end_date: '',
        company_name: '',
        position: '',
        dept_name: '',
        work_content: '',
        off_reason: '',
        work_performance: '',
        leader: '',
        subordinates_num: '',
        is_current: false
      })
    },
    removeExperienceItem(index) {
      this.temp.experience_items.splice(index, 1)
    },
    addProductItem() {
      this.temp.product_items.push({
        product_name: '',
        product_desc: '',
        start_date: '',
        end_date: '',
        is_current: false,
        product_function: '',
        product_position: '',
        product_achievement: '',
        company_name: ''
      })
    },
    removeProductItem(index) {
      this.temp.product_items.splice(index, 1)
    },
    resetData() {
      this.residence_arr = []
      this.city_arr = []
      this.temp = {
        education_items: [{
          start_date: '',
          end_date: '',
          diploma: '',
          school: '',
          major: '',
          is_unified: '0'
        }],
        experience_items: [{
          start_date: '',
          end_date: '',
          company_name: '',
          position: '',
          dept_name: '',
          work_content: '',
          off_reason: '',
          work_performance: '',
          leader: '',
          subordinates_num: '',
          is_current: false
        }],
        product_items: [{
          product_name: '',
          product_desc: '',
          start_date: '',
          end_date: '',
          is_current: false,
          product_function: '',
          product_position: '',
          product_achievement: '',
          company_name: ''
        }],
        skill_certificate_group: [''],
        report: {
          salary_structure: '',
          total_annual_salary: '',
          expected_salary: '',
          self_desc: '',
          character_desc: '',
          career_intention: '',
          expected_interview_time: '',
          expected_arrival_time: ''
        }
      }
    },
    updateDataAndSendToManager() {
      this.$refs['dataForm'].validate((valid) => {
        const update_experience_items = this.temp.experience_items.map(item => {
          if (item.is_current) {
            item.is_current = 1
          } else {
            item.is_current = 0
          }
          return item
        })
        const update_product_items = this.temp.product_items.map(item => {
          if (item.is_current) {
            item.is_current = 1
          } else {
            item.is_current = 0
          }
          return item
        })
        const update_data = {
          id: this.temp.id,
          candidate_name: this.temp.candidate_name || '',
          industry: this.temp.industry || '',
          function: this.temp.function || '',
          mobile_phone: this.temp.mobile_phone || '',
          city: this.temp.city || '',
          annual_salary: this.temp.annual_salary || '0',
          birthday_date: this.temp.birthday_date || '',
          company_name: this.temp.company_name || '',
          dept_name: this.temp.dept_name || '',
          status: this.temp.status || '',
          newest_contact_time: this.temp.newest_contact_time || '',
          graduation_date: this.temp.graduation_date || '',
          position: this.temp.position || '',
          highest_diploma: this.temp.highest_diploma || '',
          gender: this.temp.gender || '0',
          preferred_city_group: this.temp.preferred_city_group,
          company_group: [],
          language_level_group: this.temp.language_level_group,
          school_tag_group: [],
          email: this.temp.email || '',
          residence: this.temp.residence || '',
          qq: this.temp.qq || '',
          weixin: this.temp.weixin || '',
          candidate_type: this.temp.candidate_type || '',
          self_introduction: this.temp.self_introduction || '',
          training_experience: this.temp.training_experience || '',
          marriage: this.temp.marriage || '',
          skill_certificate_group: this.temp.skill_certificate_group || [],
          education_items: JSON.stringify(this.temp.education_items || []),
          experience_items: JSON.stringify(update_experience_items || []),
          product_items: JSON.stringify(update_product_items || []),
          salary_structure: this.temp.report.salary_structure || '',
          total_annual_salary: this.temp.report.total_annual_salary || '',
          expected_salary: this.temp.report.expected_salary || '',
          self_desc: this.temp.report.self_desc || '',
          character_desc: this.temp.report.character_desc || '',
          career_intention: this.temp.report.career_intention || '',
          expected_interview_time: this.temp.report.expected_interview_time || '',
          expected_arrival_time: this.temp.report.expected_arrival_time || ''
        }
        console.log(update_data)
        API.cv.update(update_data).then((response) => {
          API.cv.send_client_manager(response.data.id, response.data.cv_status).then(sub_response => {
            this.resetData()
            this.$emit('closeDialog', { type: 'update_success', data: sub_response.data })
            this.$notify({
              title: '成功',
              message: '推荐成功',
              type: 'success',
              duration: 2000
            })
          })
        })
      })
    },
    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        const update_experience_items = this.temp.experience_items.map(item => {
          if (item.is_current) {
            item.is_current = 1
          } else {
            item.is_current = 0
          }
          return item
        })
        const update_product_items = this.temp.product_items.map(item => {
          if (item.is_current) {
            item.is_current = 1
          } else {
            item.is_current = 0
          }
          return item
        })
        const update_data = {
          id: this.temp.id,
          candidate_name: this.temp.candidate_name || '',
          industry: this.temp.industry || '',
          function: this.temp.function || '',
          mobile_phone: this.temp.mobile_phone || '',
          city: this.temp.city || '',
          annual_salary: this.temp.annual_salary || '0',
          birthday_date: this.temp.birthday_date || '',
          company_name: this.temp.company_name || '',
          dept_name: this.temp.dept_name || '',
          status: this.temp.status || '',
          newest_contact_time: this.temp.newest_contact_time || '',
          graduation_date: this.temp.graduation_date || '',
          position: this.temp.position || '',
          highest_diploma: this.temp.highest_diploma || '',
          gender: this.temp.gender || '0',
          preferred_city_group: this.temp.preferred_city_group,
          company_group: [],
          language_level_group: this.temp.language_level_group,
          school_tag_group: [],
          email: this.temp.email || '',
          residence: this.temp.residence || '',
          qq: this.temp.qq || '',
          weixin: this.temp.weixin || '',
          candidate_type: this.temp.candidate_type || '',
          self_introduction: this.temp.self_introduction || '',
          training_experience: this.temp.training_experience || '',
          marriage: this.temp.marriage || '',
          skill_certificate_group: this.temp.skill_certificate_group || [],
          education_items: JSON.stringify(this.temp.education_items || []),
          experience_items: JSON.stringify(update_experience_items || []),
          product_items: JSON.stringify(update_product_items || []),
          salary_structure: this.temp.report.salary_structure || '',
          total_annual_salary: this.temp.report.total_annual_salary || '',
          expected_salary: this.temp.report.expected_salary || '',
          self_desc: this.temp.report.self_desc || '',
          character_desc: this.temp.report.character_desc || '',
          career_intention: this.temp.report.career_intention || '',
          expected_interview_time: this.temp.report.expected_interview_time || '',
          expected_arrival_time: this.temp.report.expected_arrival_time || ''
        }
        console.log(update_data)
        API.cv.update(update_data).then((response) => {
          console.log(response)
          this.resetData()
          this.$emit('closeDialog', { type: 'update_success', data: response.data })
          this.$notify({
            title: '成功',
            message: '更新成功',
            type: 'success',
            duration: 2000
          })
        })
      })
    },
    handleCancel() {
      this.$emit('closeDialog', { type: 'cancel', data: {}})
    },
    handleClose(done) {
      this.$emit('closeDialog', { type: 'cancel', data: {}})
    },
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    handlePreview(file) {
      console.log(file)
    },
    handleExceed(files, fileList) {
      this.$message.warning('当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件')
    },
    beforeRemove(file, fileList) {
      return this.$confirm('确定移除 ${ file.name }?')
    },
    loadChildrenOptions({ action, parentNode, callback }) {
      if (action === LOAD_CHILDREN_OPTIONS) {
        switch (parentNode.id) {
          default: /* empty */
            simulateAsyncOperation(() => {
              callback()
            })
        }
      }
    }
  }
}
</script>
<style scoped>
  .form-row {
    display: block;
  }
  .form-item {
    width: 40%
  }

  .form-item-full {
    width: 100%
  }
  .form-content{
    overflow:hidden;
    border: 1px solid #ddd;
    border-bottom-right-radius: 0;
    border-bottom-left-radius: 0;
    border-top-right-radius: 0;
    border-top-left-radius: 0;
    box-sizing: content-box;
    width: 80%;
    margin-left:5%;
  }
  .form-header {
    height: 40px;
    line-height: 15px;
    color: #676a6c;
    background-color: #F9F9F9;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
    border: 1px solid #ddd;
  }
  .form-table-border{
    margin: 1px 1px 1px 1px;
    border: 1px solid #ddd;
  }
  .form-header-button {
    float: right;
    margin: 0.3em 1em 0;
  } 
  .form-header-title{
    float: left;
    margin: 1.1em 1em 0.2em;
  }
  .select-item {
    display: inline-block;
    vertical-align: middle;
    width: 200px;
  }
</style>